' ======================================================================
' 执行所有测试用例
' ======================================================================
Public Sub test_all_case()
    ' ==================================================
    ' ISqlFormatterElem 接口实现测试
    ' ==================================================
    ' 测试: 非注释测试
    test_ISqlFormatterElem_unComment_elem
    ' 测试: 和前一个元素处于同一行的注释
    test_ISqlFormatterElem_ShareLineComment_elem
    ' 测试: 处于单独一行的注释
    test_ISqlFormatterElem_SingleLineComment_elem
End Sub

' ======================================================================
' ISqlFormatterElem 接口实现测试
' ======================================================================
' 测试: 非注释测试
Private Sub test_ISqlFormatterElem_unComment_elem()
    ' ==============================
    ' 1. 初始化
    ' ==============================
    ' 执行操作的 token
    Dim token As SqlToken
    Set token = New SqlToken
    Dim tokenValue As String
    tokenValue = "table1"
    token.Init tokenValue, SqlTokenType.STR_NAME 

    ' 用来执行添加操作的 token
    Dim otherToken As SqlToken
    Set otherToken = New SqlToken
    otherToken.Init "xxxx", SqlTokenType.STR_NAME

    ' 转换类型为接口类型
    Dim elem As ISqlFormatterElem
    Set elem = token

    Dim config As SqlFormatterConfiguration
    Set config = New SqlFormatterConfiguration
    ' ==============================
    ' 2. 调用方法
    ' ==============================
    ' addComponent
    elem.addComponent otherToken
    Debug.Assert token.Value = tokenValue

    ' addComponentToFirst
    elem.addComponentToFirst otherToken
    Debug.Assert token.Value = tokenValue
    
    ' canAddComponentToFirst
    Debug.Assert elem.canAddComponentToFirst = False

    ' getConditionGroups
    Debug.Assert elem.getConditionGroups Is Nothing

    ' setElemNestCount
    elem.setElemNestCount 10, config

    ' setPrefixSpaceCount
    elem.setElemNestCount 12, config

    ' hasBoundaryParenthesis
    Debug.Assert elem.hasBoundaryParenthesis = True

    ' addBoundaryLeftParenthesis
    elem.addBoundaryLeftParenthesis
    elem.addBoundaryLeftParenthesis 2
    Debug.Assert token.Value = tokenValue

    ' addBoundaryRightParenthesis
    elem.addBoundaryRightParenthesis
    elem.addBoundaryRightParenthesis 2
    Debug.Assert token.Value = tokenValue

    ' getType
    Debug.Assert elem.getType = SqlTokenType.STR_NAME 

    ' isComment
    Debug.Assert elem.isComment = False

    ' isShareLineComment
    Debug.Assert elem.isShareLineComment = False

    ' isSingleLineComment
    Debug.Assert elem.isSingleLineComment = False

    ' isEndsWithComment
    Debug.Assert elem.isEndsWithComment = False

    ' isMultiLine
    Debug.Assert elem.isMultiLine = False

    ' toString
    Debug.Assert elem.toString(config) = tokenValue

    ' toStringArray
    Dim strArr As IPrimitiveArrayRef
    Set strArr = elem.toStringArray(config)
    Debug.Assert strArr.Count = 1
    Debug.Assert strArr.Item(0) = tokenValue
End Sub

' 测试: 和前一个元素处于同一行的注释
Private Sub test_ISqlFormatterElem_ShareLineComment_elem()
    ' ==============================
    ' 1. 初始化
    ' ==============================
    ' 执行操作的 token
    Dim token As SqlToken
    Set token = New SqlToken
    Dim tokenValue As String
    tokenValue = "-- abcd"
    token.Init tokenValue, SqlTokenType.SHARE_LINE_COMMENT 

    ' 用来执行添加操作的 token
    Dim otherToken As SqlToken
    Set otherToken = New SqlToken
    otherToken.Init "xxxx", SqlTokenType.STR_NAME

    ' 转换类型为接口类型
    Dim elem As ISqlFormatterElem
    Set elem = token

    Dim config As SqlFormatterConfiguration
    Set config = New SqlFormatterConfiguration
    ' ==============================
    ' 2. 调用方法
    ' ==============================
    ' addComponent
    elem.addComponent otherToken
    Debug.Assert token.Value = tokenValue

    ' addComponentToFirst
    elem.addComponentToFirst otherToken
    Debug.Assert token.Value = tokenValue
    
    ' canAddComponentToFirst
    Debug.Assert elem.canAddComponentToFirst = False

    ' getConditionGroups
    Debug.Assert elem.getConditionGroups Is Nothing

    ' setElemNestCount
    elem.setElemNestCount 10, config

    ' setPrefixSpaceCount
    elem.setElemNestCount 12, config

    ' hasBoundaryParenthesis
    Debug.Assert elem.hasBoundaryParenthesis = True

    ' addBoundaryLeftParenthesis
    elem.addBoundaryLeftParenthesis
    elem.addBoundaryLeftParenthesis 2
    Debug.Assert token.Value = tokenValue

    ' addBoundaryRightParenthesis
    elem.addBoundaryRightParenthesis
    elem.addBoundaryRightParenthesis 2
    Debug.Assert token.Value = tokenValue

    ' getType
    Debug.Assert elem.getType = SqlTokenType.SHARE_LINE_COMMENT 

    ' isComment
    Debug.Assert elem.isComment = True

    ' isShareLineComment
    Debug.Assert elem.isShareLineComment = True

    ' isSingleLineComment
    Debug.Assert elem.isSingleLineComment = False

    ' isEndsWithComment
    Debug.Assert elem.isEndsWithComment = True

    ' isMultiLine
    Debug.Assert elem.isMultiLine = False

    ' toString
    Debug.Assert elem.toString(config) = tokenValue

    ' toStringArray
    Dim strArr As IPrimitiveArrayRef
    Set strArr = elem.toStringArray(config)
    Debug.Assert strArr.Count = 1
    Debug.Assert strArr.Item(0) = tokenValue
End Sub

' 测试: 处于单独一行的注释
Private Sub test_ISqlFormatterElem_SingleLineComment_elem()
    ' ==============================
    ' 1. 初始化
    ' ==============================
    ' 执行操作的 token
    Dim token As SqlToken
    Set token = New SqlToken
    Dim tokenValue As String
    tokenValue = "-- abcd"
    token.Init tokenValue, SqlTokenType.SINGLE_LINE_COMMENT 

    ' 用来执行添加操作的 token
    Dim otherToken As SqlToken
    Set otherToken = New SqlToken
    otherToken.Init "xxxx", SqlTokenType.STR_NAME

    ' 转换类型为接口类型
    Dim elem As ISqlFormatterElem
    Set elem = token

    Dim config As SqlFormatterConfiguration
    Set config = New SqlFormatterConfiguration
    ' ==============================
    ' 2. 调用方法
    ' ==============================
    ' addComponent
    elem.addComponent otherToken
    Debug.Assert token.Value = tokenValue

    ' addComponentToFirst
    elem.addComponentToFirst otherToken
    Debug.Assert token.Value = tokenValue
    
    ' canAddComponentToFirst
    Debug.Assert elem.canAddComponentToFirst = False

    ' getConditionGroups
    Debug.Assert elem.getConditionGroups Is Nothing

    ' setElemNestCount
    elem.setElemNestCount 10, config

    ' setPrefixSpaceCount
    elem.setElemNestCount 12, config

    ' hasBoundaryParenthesis
    Debug.Assert elem.hasBoundaryParenthesis = True

    ' addBoundaryLeftParenthesis
    elem.addBoundaryLeftParenthesis
    elem.addBoundaryLeftParenthesis 2
    Debug.Assert token.Value = tokenValue

    ' addBoundaryRightParenthesis
    elem.addBoundaryRightParenthesis
    elem.addBoundaryRightParenthesis 2
    Debug.Assert token.Value = tokenValue

    ' getType
    Debug.Assert elem.getType = SqlTokenType.SINGLE_LINE_COMMENT 

    ' isComment
    Debug.Assert elem.isComment = True

    ' isShareLineComment
    Debug.Assert elem.isShareLineComment = False

    ' isSingleLineComment
    Debug.Assert elem.isSingleLineComment = True

    ' isEndsWithComment
    Debug.Assert elem.isEndsWithComment = True

    ' isMultiLine
    Debug.Assert elem.isMultiLine = False

    ' toString
    Debug.Assert elem.toString(config) = tokenValue

    ' toStringArray
    Dim strArr As IPrimitiveArrayRef
    Set strArr = elem.toStringArray(config)
    Debug.Assert strArr.Count = 1
    Debug.Assert strArr.Item(0) = tokenValue
End Sub
